<template>
    <div class="login-form login-signin">
              <div class="pb-13 pt-lg-0 pt-5">
                <h3
                  class="font-weight-bolder text-dark font-size-h4 font-size-h1-lg"
                >
                  欢迎来到乐游实战平台
                </h3>
              </div>
              <div class="form-group">
                <div class="d-flex justify-content-between mt-n5">
                  <label class="font-size-h6 font-weight-bolder text-dark pt-5"
                    >邮箱</label
                  >
                  <a
                    @click="openRegister()"
                    class="text-primary font-size-h6 font-weight-bolder text-hover-primary pt-5"
                    >没有账号 ?</a
                  >
                </div>
                <div
                  id="example-input-group-2"
                  label=""
                  label-for="example-input-2"
                >
                  <input
                    class="form-control form-control-solid h-auto py-7 px-6 rounded-lg"
                    type="text"
                    name="password"
                    ref="password"
                    v-model="email"
                    autocomplete="off"
                  />
                </div>
              </div>
              <div class="form-group">
                <div class="d-flex justify-content-between mt-n5">
                  <label class="font-size-h6 font-weight-bolder text-dark pt-5"
                    >密码</label
                  >
                  <a
                    class="text-primary font-size-h6 font-weight-bolder text-hover-primary pt-5"
                    >忘记密码 ?</a
                  >
                </div>
                <div
                  id="example-input-group-2"
                  label=""
                  label-for="example-input-2"
                >
                  <input
                    class="form-control form-control-solid h-auto py-7 px-6 rounded-lg"
                    type="password"
                    name="password"
                    v-model="password"
                    autocomplete="off"
                  />
                </div>
              </div>
              <div class="pb-lg-0 pb-5">
                <button
                  class="btn btn-primary font-weight-bolder font-size-h6 px-15 py-4 my-3 mr-3"
                  @click="login()"
                >
                  登 陆
                </button>
              </div>
            </div>
</template>
<script>
import axios from "axios";
import Swal from "sweetalert2";
export default {
  name: "LoginForm",
  data() {
    return {
      email: "lyhkeven@126.com",
      password: "123",
    };
  },
  created() {},
  methods: {
    login() {
      this.$axios({
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
        },
        url: "/api/login", //后端请求的路径
        method: "post",
        data: {
          email: this.email,
          password: this.password,
        },
      }).then((response) => {
        console.log(response.username);
        let systemToken = response.token;
        if (systemToken != null) {
          sessionStorage.setItem("systemToken", systemToken);
          this.$router.push("/dashboard");
          this.$notify({
            title: "登录成功",
            message: "欢迎" + response.username,
          });
        }
      });
    },
    openRegister() {
        this.$parent.openRegisterForm()
    },
  },
};
</script>
